package com.chujian.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.chujian.dao.FoodDao;
import com.chujian.daoImpl.FoodDaoImpl;
import com.google.gson.Gson;

/**
 * Servlet implementation class FoodCategary
 */
@WebServlet("/FoodCategaryServlet")
public class FoodCategaryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       List<String> listCategary;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FoodCategaryServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 FoodDao dao=new FoodDaoImpl();
		 listCategary= dao.getAllCategary();
		 Gson gson=new Gson();
		 String listJson=gson.toJson(listCategary);
		 response.setContentType("text/html;charset=UTF-8");
		 PrintWriter out=response.getWriter();
		 out.write(listJson);
		 System.out.println(listJson);
	}

}
